﻿using System;
using API.Interfaces;
using Framework.Business;
using Framework.Extensions;
using RealDataReceiver.Business;
using RealDataReceiver.DataAccess;
using RealDataReceiver.Entities;

namespace RealDataReceiver.Service
{
    public class RealDataReceiverService : RestServiceBase<RealDataReceiverRequest>
    {
        public override object OnPost(RealDataReceiverRequest request)
        {
            var response = new RealDataReceiverResponse();
            try
            {
                var ctx = new ServiceContextBase<RealDataReceiverRequest, RealDataReceiverResponse>(request, response);

                var rawString = RequestContext.GetInputStreamAsString();

                ctx.RawInputString = rawString;

                RealDataReceiveBusiness.RealDataProcess(ctx);

                //response.Memo = ChannelDA.Instance.GetLocationName("25").ToString();//Test Code

                //response.Message = RealDataReceiveBusiness.ConvertRawdataToMessage(rawString);

                response.Result = true;
                response.Succeeded = true;
            }
            catch (Exception e)
            {
                response.CaptureException(e);
            }

            return response;
        }
    }
}
